home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
ctutor.exe
/
ANSWERS
/
CH11_1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-15
|
1KB
|
54 lines
#include "stdio.h"
#include "string.h"
void main()
{
struct {
char what[25];
int legs, arms;
} object[6];
int index;
strcpy(object[0].what, "human being");
object[0].legs = 2;
object[0].arms = 2;
strcpy(object[1].what, "dog");
object[1].legs = 4;
object[1].arms = 0;
strcpy(object[2].what, "television set");
object[2].legs = 4;
object[2].arms = 0;
strcpy(object[3].what, "chair");
object[3].legs = 4;
object[3].arms = 2;
strcpy(object[4].what, "centipede");
object[4].legs = 100;
object[4].arms = 0;
strcpy(object[5].what, "spider");
object[5].legs = 6;
object[5].arms = 0;
for(index = 0 ; index < 6 ; index++) {
printf("A %s has %d legs and %d arms.\n", object[index].what,
object[index].legs, object[index].arms);
}
}
/* Result of execution
A human being has 2 legs and 2 arms.
A dog has 4 legs and 0 arms.
A television set has 4 legs and 0 arms.
A chair has 4 legs and 2 arms.
A centipede has 100 legs and 0 arms.
A spider has 6 legs and 0 arms.
*/